﻿using System.Configuration;
using System.Data.SqlClient;
using System;

namespace CharacterCreation.Data {
    public class ConnectionBuilder {
        public static string ConnectionString {
            get {
                return ConfigurationManager.ConnectionStrings["CharacterDatabase"].ConnectionString;
            }
        }

        public static SqlConnection CreateConnection() {
            return new SqlConnection(ConnectionString);
        }

        public void Try() {
            SqlConnection conn = new SqlConnection(ConnectionString);

            try {
                conn.Open();

                SqlCommand command = new SqlCommand("create table character (ID uniqueidentifier primary key)", conn);
                command.ExecuteNonQuery();
            }
            catch {
                throw new Exception("failed to open the connection");
            }
            finally{
                if (conn.State == System.Data.ConnectionState.Open)
                    conn.Close();
            }
        }
    }
}
